package cn.tedu._04mvcweibo.config;

import cn.tedu._04mvcweibo.interceptor.AuthFilter;
import cn.tedu._04mvcweibo.interceptor.TimeAccessInterceptor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**Spring MVC配置类*/
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * @Bean 注解描述的方法,其返回值会以Bean对象的形式交给Spring管理
     * @return
     */
   @Bean
   public FilterRegistrationBean filterRegistrationBean(){
       FilterRegistrationBean bean=
               new FilterRegistrationBean(new AuthFilter());
       bean.addUrlPatterns("/v1/weibo/insert");
       return bean;
   }

    //添加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TimeAccessInterceptor())
                .addPathPatterns("/v1/users/reg");//要拦截的路径
    }

}
